using System;
namespace ShellID3Reader
{
	internal struct ShellID3TagReader
	{
		internal static MP3File ReadID3Tags(string FileFullPath){
			MP3File mp3File = new MP3File();

			//parse file name
			string fileName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\")+1);
			//parse file path
			string filePath = FileFullPath.Substring(0,FileFullPath.LastIndexOf("\\"));
			//create shell instance
			Shell32.Shell shell = new Shell32.Shell();
			//set the namespace to file path
			Shell32.Folder folder = shell.NameSpace(filePath);
			//get ahandle to the file
			Shell32.FolderItem folderItem = folder.ParseName(fileName);
			//did we get a handle ?
			if (folderItem !=null){
				mp3File.FileName = fileName;
				//query information from shell regarding file
				mp3File.ArtistName = folder.GetDetailsOf(folderItem,9);
				mp3File.AlbumName = folder.GetDetailsOf(folderItem,17);
				mp3File.SongTitle = folder.GetDetailsOf(folderItem,10);
				mp3File.TrackNumber = Int32.Parse(folder.GetDetailsOf(folderItem,19));
			}
			//clean ip
			folderItem = null;
			folder = null;
			shell = null;
			//return mp3File instance
			return mp3File;
		}
	}
}
